package com.prince.web.controller;

import com.prince.aspect.AppLog;
import com.prince.model.Unit;
import com.prince.page.Page;
import com.prince.web.base.BaseController;
import com.prince.web.base.SessionUtil;
import com.prince.web.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 功能描述: 计量单位
 * @Author: 王培喜 58528792@163.com
 * @Date: 2021/4/6 14:26
 */
@Controller
@Validated
public class UnitController extends BaseController {

    @Autowired
    private UnitService unitService;
    /**
     * 功能描述: 分页查询计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 15:25
     */
    @AppLog
    @PostMapping("/findUnitByPage")
    public ResponseEntity<Map<String,Object>> findUnitByPage(@RequestParam Map<String,Object> params) {
        Page page = this.getRequestPageRollInfo(params);
        Map<String,Object> map = unitService.findUnitByPage(params,page);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }

    /**
     * 功能描述: 添加计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/addUnit")
    public ResponseEntity<Map<String,Object>> addUnit(Unit unit) {
        unit.setCreater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = unitService.addUnit(unit);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 修改计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/updateUnit")
    public ResponseEntity<Map<String,Object>> updateUnit(Unit unit) {
        unit.setUpdater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = unitService.updateUnit(unit);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 删除计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/delUnit")
    public ResponseEntity<Map<String,Object>> delUnit(Unit unit) {
        unit.setUpdater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = unitService.delUnit(unit);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 通过id查询计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/findUnitById")
    public ResponseEntity<Map<String,Object>> findUnitById(@NotNull Integer id) {
        Map<String,Object> map = unitService.findUnitById(id);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }

    /**
     * 功能描述: 查询所有计量单位
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/findUnitAll")
    public ResponseEntity<Map<String,Object>> findUnitAll() {
        Map<String,Object> map = unitService.findUnitAll();
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }
}
